﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace PointAnalyze
{
    public partial class Form1 : Form
    {
        Stopwatch watch = new Stopwatch();
        Queue<byte> colors = new Queue<byte>();
        public Form1()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint |
                    ControlStyles.OptimizedDoubleBuffer |
                    ControlStyles.UserPaint, true);
            InitializeComponent();

            watch.Start();
        }
        byte color = 100;
        bool add = true;
        byte colorTarget = 0;
        Random r = new Random();
        float x = 0, y = 0, angle = 0;
        Point center = new Point(200, 200);
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics G = e.Graphics;
            G.Clear(Color.Black);
            //G.FillEllipse(new SolidBrush(Color.White), 100, 100, 3, 3);
            Brush brush = new SolidBrush(Color.FromArgb(color, color, color));
            G.FillRectangle(brush, this.ClientSize.Width / 2 + x, this.ClientSize.Height / 2 + y, 2, 2);
            brush.Dispose();

            int index = 100;
            foreach (byte c in colors)
            {
                Brush b = new SolidBrush(Color.FromArgb(c * 5, c * 5, c * 5));
                G.FillRectangle(b, index-- * 2, (52 - c) * 2, 2, 2);
                b.Dispose();
            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Text = watch.ElapsedMilliseconds.ToString();
            #region 时间上的颜色变化
            //color = (byte)r.Next(256);//随机突变

            //if (color > colorTarget * 5)
            //    color -= 5;
            //if (color < colorTarget * 5)
            //    color += 5;
            //else
            //    colorTarget = (byte)r.Next(52);//随机渐变

            //if (color == 0) add = true;
            //else if (color == 255) add = false;
            //if (add) color += 5; else color -= 5;//渐增渐减

            //color = (byte)(color % byte.MaxValue);//渐增
            //color += 5;

            //if (color == 0) color = 255; else color = 0; //出现与消失

            if (colors.Count >= 100) colors.Dequeue();
            colors.Enqueue((byte)(color / 5));//图谱
            #endregion

            #region 空间上的坐标变化
            //x += 1;
            //x %= 100;//水平匀速直线运动
            //y += 1;
            //y %= 100;//垂直匀速直线运动

            //x = (float)(100 * Math.Cos(angle * Math.PI / 180));//匀速圆周运动
            //y = (float)(100 * Math.Sin(angle * Math.PI / 180));
            //angle += 1;
            #endregion


            this.Invalidate();
            watch.Reset();
            watch.Start();
        }
    }
}
